﻿module EmailValidationTests

open System
open System.IO
open System.Xml
open FsUnit
open EmailValidation.EmailValidator

type EmailTest = {id: string; address: string; valid: bool}
    
let nodeValue (n: XmlNode) s =
    (n.SelectSingleNode s).InnerText

let validateEmails () =
    let doc = XmlDocument()
    doc.Load "..\..\email-tests.xml"
    let allSpecs = doc.SelectNodes "tests/test"
                    |> Seq.cast<XmlNode>
                    |> Seq.map (fun n -> {id = nodeValue n "id"; address = nodeValue n "address"; valid = bool.Parse (nodeValue n "valid")})
                    |> Seq.map (fun t -> spec (sprintf "ID %A: %A" t.id t.address) (isValidEmail t.address |> should equal t.valid))
        
    specs "Email validation" allSpecs
    printfn "%s" (Results.summary())
